package com.weichuang.service;

import com.weichuang.domain.User;
import com.weichuang.mapper.UserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class UserServiceDemo {
    public static void main(String[] args) throws IOException {
        //获取核心配置文件
        InputStream resourceAsStream = Resources.getResourceAsStream("sqlMapConfig.xml");
        //获取session工厂对象
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        //获取session会话对象
        SqlSession sqlSession = sqlSessionFactory.openSession();
        //获取Mybatis框架生成的UserMapper接口的实现类
        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
        //模拟用户查询条件
        /*User user = new User();
        //user.setId(3);
        user.setUsername("索隆");
        *//*user.setPassword("1234");*//*
        List<User> userList = userMapper.findByCondition(user);
        System.out.println(userList);*/

        //模拟前端传的参数
        List<Integer> ids = new ArrayList<>();
        ids.add(1);
        ids.add(3);
        ids.add(7);
        List<User> byIds = userMapper.findByIds(ids);
        System.out.println(byIds);

    }
}
